package cn.virens.web.components.beetl.format;

import org.beetl.core.Format;

public class ImageFormat implements Format {
	public static final String DEF_AVATAR = "/assets/img/avatar.png";
	public static final String DEF_IAMGE = "/assets/img/default.png";

	@Override
	public Object format(Object data, String pattern) {
		if ("avatar".equals(pattern)) {
			return format(data, "/down/thumb/", DEF_AVATAR);
		} else if ("src".equals(pattern)) {
			return format(data, "/down/image/", DEF_IAMGE);
		} else {
			return format(data, "/down/thumb/", DEF_IAMGE);
		}
	}

	private static String format(Object data, String prefix, String def) {
		if (data != null && !"".equals(data)) {
			return prefix + data;
		} else {
			return def;
		}
	}
}
